import mongoose from '../config/DBHelper'
import moment from 'moment'
const Schema = mongoose.Schema
const SignSchema = new Schema({
  uid: { type: String, ref: 'user' },
  created: { type: Date },
  fav: { type: Number }
  // last_sign: { type: Date }
})

SignSchema.pre('save', function (next) {
  this.created = moment().format('YYYY-MM-DD HH:mm:ss')
  next()
})
SignSchema.statics = {
  findByUid (uid) {
    return this.findOne({
      uid
    }).sort({ created: -1 })
  }
}

const SignRecord = mongoose.model('sign_record', SignSchema)

export default SignRecord
